﻿using SqlSugar;

namespace StoreSQLSugar_API.Services
{
    public interface IBaseService<T> where T : class, new() 
    {
        /// <summary>
        /// 添加一个模型
        /// </summary>
        /// <param name="model">模型</param>
        /// <returns>是否成功，true成功，false失败</returns>
        bool Add(T model);

        /// <summary>
        /// 修改一个模型
        /// </summary>
        /// <param name="model">模型</param>
        /// <returns>是否成功，true成功，false失败</returns>
        bool Update(T model);

        /// <summary>
        /// 根据一个主键删除一个模型
        /// </summary>
        /// <param name="primaryKey">主键</param>
        /// <returns>是否成功，true成功，false失败</returns>
        bool Delete(int primaryKey);

        /// <summary>
        /// 根据一个主键获取一个模型
        /// </summary>
        /// <param name="primaryKey">主键</param>
        /// <returns>模型</returns>
        T GetModel(int primaryKey);

        /// <summary>
        /// 获取所有模型
        /// </summary>
        /// <param name="exp">查询表达式</param>
        /// <returns>列表</returns>
        List<T> GetListAll(Expressionable<T> exp);

        /// <summary>
        /// 获取分页模型
        /// </summary>
        /// <param name="exp">查询表达式</param>
        /// <param name="totalPage">总页数</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">条数</param>
        /// <returns>列表</returns>
        List<T> GetList(Expressionable<T> exp, out int totalPage, int pageIndex = 1, int pageSize = 10);
    }
}
